# Python 2.6.4
# Project Euler, Problem 86
# Copyright 2010 Talha Zaman

from mine import PPT
tri = PPT()
lim = 2000
M = [0]*lim
for i in range(lim):
    a, b, c = A, B, C = tri.next()
    while a<lim or b<lim:
        if a<lim and b<2*a: M[a] += abs(b/2-(b-a)) + 1
        if b<lim and a<2*b: M[b] += a/2
        a, b, c = a+A, b+B, c+C
i, s = 0, 0
while s<1000000: i, s = i+1, s+M[i]
print i-1
